package com.iris.live.services.report.data;

import com.iris.live.services.data.models.ReportConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @Description:报表数据服务
 * @author: Tony.Zhang
 * @Date: 2017-08-11 12:08
 **/
@Component
public class ReportDataServiceImpl implements IReportDataService {
    private static Logger logger = LoggerFactory.getLogger(ReportDataServiceImpl.class);

    @Override
    public List getData(ReportContext context, List<ReportConfig> configs, IReportDataSource source) throws Exception {
        List result = new ArrayList();

        long startTime = System.currentTimeMillis();
        //获取报表原始数据
        List<Map> datas = source.getData(context, configs);
        logger.warn("Getting time used={}", (System.currentTimeMillis() - startTime)/1000);

        startTime = System.currentTimeMillis();
        result.addAll(context.getConvertor().convert(context, configs, datas));
        logger.warn("Converting time used={}", (System.currentTimeMillis() - startTime)/1000);

        return result;
    }
}